package com.nitor.dns.validate;

import java.util.StringTokenizer;

import org.xbill.DNS.Name;
import org.xbill.DNS.TextParseException;

public class DNS_Parser {
	
	public Name getDomain(String addr) throws TextParseException{
		if(addr.contains("@")){
			String domainName = null;
			StringTokenizer tok = new StringTokenizer(addr,"@");
			while(tok.hasMoreTokens()){
				domainName = tok.nextToken();
			}
			if(domainName != null)
				return new Name(domainName + ".");
			else throw new TextParseException();
		}else return new Name(addr+".");
	}
	
	public Name getAddress(String addr) throws TextParseException{
		if(addr.contains("@")){
			return new Name(addr.replace("@", ".")+".");
		}else return new Name(addr + ".");
	}
}
